home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Beziers y otros splines / BezierArt / BezierArt.cs next >
Encoding:
Text File  |  2002-05-07  |  1.2 KB  |  44 lines

  1. //----------------------------------------
  2. // BezierArt.cs ⌐ 2001 by Charles Petzold
  3. //----------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class BezierArt: PrintableForm
  9. {
  10.      const int iNum = 100;
  11.  
  12.      public new static void Main()
  13.      {
  14.           Application.Run(new BezierArt());
  15.      }
  16.      public BezierArt()
  17.      {
  18.           Text = "Arte Bezier";
  19.      }
  20.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  21.      {
  22.           Pen      pen  = new Pen(clr);
  23.           PointF[] aptf = new PointF[4];
  24.  
  25.           for (int i = 0; i < iNum; i++)
  26.           {
  27.                double dAngle = 2 * i * Math.PI / iNum;
  28.  
  29.                aptf[0].X =     cx / 2 + cx /  2 * (float) Math.Cos(dAngle);
  30.                aptf[0].Y = 5 * cy / 8 + cy / 16 * (float) Math.Sin(dAngle);
  31.  
  32.                aptf[1] = new PointF(cx / 2,    -cy);
  33.                aptf[2] = new PointF(cx / 2, 2 * cy);
  34.  
  35.                dAngle += Math.PI;
  36.  
  37.                aptf[3].X = cx / 2 + cx /  4 * (float) Math.Cos(dAngle);
  38.                aptf[3].Y = cy / 2 + cy / 16 * (float) Math.Sin(dAngle);
  39.  
  40.                grfx.DrawBeziers(pen, aptf);
  41.           }
  42.      }
  43. }
  44.